<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<style>
	#moreBtn{
	
	}

</style>
<script>
	function commentView(comentId){
		var i = document.getElementById(comentId);
		var name = i.getAttribute("name");
		i.setAttribute("class",'commentView1');
		if(name == null){
		
			 i.style.display= "block";
			 i.setAttribute("name",comentId);
		}else{
			 i.style.display= "none";
			 i.removeAttribute("name");
			 for(var i = 0 ;i<document.forms[0].length;i++ )
			 if("re"==document.forms[0].Element[i].getAttribute("class")){
				 document.forms[0].Element[i].value=0;
			 }
		}
	
	}
	
	function commentAdd(){
		
		var url = "/ControlerServlet";
		var param = "cmd="+encodeURIComponent("replyAdd");
		sendRequest(url, param, res, "post", true);
		
		
		
	}
	function res(){
		
		if(xhr.readyState == 200 && xhr.status==4){
			
			document.getElementById("commentAddView");
		}
		
	}
</script>
<style type="text/css">
.commentView td{
		padding-left:10px;
	}

	
}
td.moreView{
	text-align: center;
	background-color:#dec6df;
	border:2px solid  #cca8ce;
}
#reply{
	width:100%;
}	

thead {
	text-align: center;
}
tbody tr.comment{

	text-align: center;
}
</style>	
</head>

	<table   id="reply">
		<thead style="border: 1px solid #76c1da;">
			<tr>
				<th>글번호</th>
				<th>내용</th>
				<th>작성자</th>
				<th>날짜</th>
			</tr>
		</thead>
		<tbody class="tborder">
			<c:forEach var="item" items="${bbsList}" varStatus="num">
				<tr id="content${item.idx}" class=comment>
					<td>${num.count}</td>
					
						<td><a href="javascript:commentView('comment${item.idx}')">${item.content}</a></td>
					
					<td>${item.content}</td>
					<td>${item.writer}</td>
					<td>${item.write_date}</td>					
				</tr>
				<tr id="comment${item.idx}" class="commentView" style="display:none;" >
					<td colspan=4>
						<c:forEach var="comment" items="${item.ct_list}" varStatus="index">
							<pre>┗   ${comment.content}</pre>
				 		</c:forEach>
				 		<pre class="commentAddView">
				 		</pre>
				 		<br/>
				 		<form action="/ControlerServlet" method="post">
				 			<label>-----------------------------------------------------</label><br/>
				 					* 댓글 달기<br/>
				 			<label>-----------------------------------------------------</label><br/>
				 			아이디 : <input type="text" name="c_name" id="c_name" size="7" class="re">&nbsp;&nbsp;
				 			비밀번호 : <input type="password" value="0000" name="c_pwd" id="c_pwd" size="2" class="re">&nbsp;&nbsp;&nbsp;
				 			ip : <%=request.getRemoteAddr()%>
				 			<textarea rows="4" cols="30" id="c_content" class="re"></textarea><br/>
				 			<input type="hidden" name="cmd" value="replyAdd"/>
				 			<input type="hidden" name="bbs_idx" value="${item.idx}"/>
				 			<input type="button" value="전송하기" id="subBtn" onclick="javascript:commentAdd()"/>
				 			
				 			
				 			
				 			
				 		</form>
				 		
				 	</td>
				 </tr>
			</c:forEach>
		</tbody>
		<tfoot>
		<tr>
			<td colspan="4" class="moreView">
				<label onclick="javascript:moreView()">20개 더보기</label>
			<td>
		</tr>
		</tfoot>
	</table>

